<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <script src="../axios.js"></script>
</head>
<body>
    <div id="box">
        <button @click="handleClick">axios</button>
    </div>
</body>
<script>
    let obj = {
        data(){

        },
        methods: {
            handleClick(){
                // console.log(axios);
                // get方法
                axios.get('http://localhost:3000/list').then(res=>{
                    console.log(res.data);//res是响应的内容,data是真实数据
                }).catch(err=>{
                    console.log(err);
                })
                // post-JSON格式
                axios.post('http://localhost:3000/list',{  //发送JSON格式数据
                    name:'zhangsan',
                    age:19
                }).then(res=>{
                    console.log(res.data);
                }).catch(err=>{
                    console.log(err);
                })
                //post-form格式
                axios.post('http://localhost:3000/list','name=zhangsan&age=19').then(res=>{
                    console.log(res.data);
                }).catch(err=>{
                    console.log(err);
                })
                //put格式
                axios.put('http://localhost:3000/list/6','name=zhangsan&age=19').then(res=>{
                    console.log(res.data);
                }).catch(err=>{
                    console.log(err);
                })
                //delete格式
                axios.delete('http://localhost:3000/list/6').then(res=>{
                    console.log(res.data);
                }).catch(err=>{
                    console.log(err);
                })
                //axios完整版请求
                axios({
                    method:'put',
                    url:'http://localhost:3000/list/5',
                    data:{  //不需要参数时可以不添加
                        'name':'zhangsan',
                        'age':19
                    }
                }).then(res=>{
                    console.log(res);
                })
            }
        },
    }
    let app = Vue.createApp(obj).mount('#box');
</script>
</html>